package com.content.scaffold.common.config.obs;

import com.content.scaffold.common.constants.ObsClientConstant;
import com.notary.ossservice.service.FileService;
import com.notary.ossservice.service.NotaryObsClient;
import com.notary.ossservice.service.impl.ObsFileServiceImpl;
import com.obs.services.ObsClient;
import com.obs.services.ObsConfiguration;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author xiaojl
 */
@Configuration
@Slf4j
public class ObsClientConfig {
    @Resource
    ObsClientConstant obsClientConstant;


    @Bean(name = "osFileService")
    public FileService fileService() {
        log.info("huawei obs fileService loading.........");
        ObsConfiguration config = new ObsConfiguration();
        config.setEndPoint(obsClientConstant.getEndPoint());
        config.setIdleConnectionTime(25000);
        ObsClient obsClient = new ObsClient(obsClientConstant.getAk(), obsClientConstant.getSk(), config);
        NotaryObsClient notaryObsClient = new NotaryObsClient();
        notaryObsClient.setObsClient(obsClient);
        notaryObsClient.setDefaultBucket(obsClientConstant.getDefaultBucket());
        return new ObsFileServiceImpl(notaryObsClient);
    }

}
